/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.batavia.inter.impl;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.sun.jmx.remote.internal.ClientCommunicatorAdmin;
import java.util.Date;
import java.util.List;
import org.batavia.domain.Flight;
import org.batavia.inter.InterfaceAirlines;
import org.joda.time.DateTime;

/**
 *
 * @author omenk
 */
public class AirlinesImpl implements InterfaceAirlines {

    public List<Flight> search(Date departure, String origin, String destination, Integer adult, Integer infant) {


        try {


            HtmlForm form = LoginImpl.page2.getFormByName("searchbook");

            form.getSelectByName("ruteBerangkat").setSelectedAttribute(origin, true);
            form.getSelectByName("ruteTujuan").setSelectedAttribute(destination, true);

            DateTime depart = new DateTime(departure);

            form.getSelectByName("tglBerangkatPergi").setSelectedAttribute(depart.getDayOfMonth() + "-", true);
            form.getSelectByName("blnBerangkatPergi").setSelectedAttribute(depart.getMonthOfYear() + "-", true);
            form.getSelectByName("thnBerangkatPergi").setSelectedAttribute(depart.getYear() + "", true);
            form.getSelectByName("jmlPenumpang").setSelectedAttribute(adult.toString(), true);

            final HtmlSubmitInput button = form.getInputByName("Submit");
            final HtmlPage page3 = button.click();

            System.out.println(page3.asText());
            System.out.println(page3.getUrl());
            page3.getFormByName("pilihPenerbangan");

            

            List<HtmlElement> flatNo = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_FLTNO);
            List<HtmlElement> dep = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_DEP);
            List<HtmlElement> arr = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_ARR);
            List<HtmlElement> via = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_VIA);

            List<HtmlElement> z = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_Z);

            List<HtmlElement> w = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_W);
            List<HtmlElement> p = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_P);
            List<HtmlElement> n = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_N);
            List<HtmlElement> x = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_X);
            List<HtmlElement> r = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_R);
            List<HtmlElement> s = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_S);
            List<HtmlElement> t = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_T);
            List<HtmlElement> v = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_V);
            List<HtmlElement> q = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_Q);
            List<HtmlElement> b = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_B);
            List<HtmlElement> l = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_L);
            List<HtmlElement> m = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_N);
            List<HtmlElement> h = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_H);
            List<HtmlElement> d = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_D);
            List<HtmlElement> y = (List<HtmlElement>) page3.getByXPath(BataConstants.XPATH_Y);


            //System.out.println(page3.asText());



            // loginImpl.client.closeAllWindows();




        } catch (Exception e) {
            System.out.println("" + e);

        }

        return null;


    }
}
